package com.example.novelstory.service.lxy;

//import com.example.novelstory.dao.lxy.BookShelfDao;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.novelstory.dao.lxy.BookShelfDao;
import com.example.novelstory.entity.BookShelf;
import com.example.novelstory.entity.Novel;
import com.example.novelstory.utill.Constants;
import com.example.novelstory.utill.Result;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

@Service
public class BookShelfServImpl extends ServiceImpl<BookShelfDao,BookShelf> {
//    @Autowired
//    BookShelfDao bookShelfDao;
//    书架全查
//    @Override
    public List<BookShelf> UserBook() {
//        List<BookShelf> bookShelfList=bookShelfDao.UserBook();
        return list();
    }
//添加书籍
//    @Override
    public boolean bookinsert(BookShelf bookShelf) {
//        String bookname = title;
//        int insertUser= bookShelfDao.bookinsert(author_id, bookname);
//        if (insertUser == 1){
//            List<BookShelf> userList=bookShelfDao.UserBook();
//            return userList;
//        }else {
//            return null;
//        }
        return save(bookShelf);
    }

////    @Override
//    public boolean bookdelete(BookShelf bookShelf) {
////        int bookdelete= bookShelfDao.bookdelete(title);
////        if (bookdelete==1){
////            List<BookShelf> bookShelfList=bookShelfDao.UserBook();
////        return bookShelfList;
////        }else {
////            System.out.println("删除失败，请重试");
////            return null;
////        }
//
//        QueryWrapper queryWrappergetone=new QueryWrapper<>();
//        queryWrappergetone.eq("title",bookShelf.getTitle());
//        return remove(queryWrappergetone);
//        BookShelf bookShelfgetone = getOne(queryWrappergetone);
//        if (bookShelfgetone != null){
//            int getonId = bookShelfgetone.getId();
//            return removeById(getonId);
//        } else {
//            return false;
//        }
//    }
    //    @Override
    public Result bookdelete(BookShelf bookShelf) {
        QueryWrapper queryWrappergetone=new QueryWrapper<>();
        queryWrappergetone.eq("title",bookShelf.getTitle());
        boolean res = remove(queryWrappergetone);
        if (res != false){
            return Result.success(Constants.CODE_200,"删除成功");
        } else {
            return Result.error(Constants.CODE_600,"删除失败");
        }
    }

    public Result bookSelfLikeSearch(BookShelf bookShelf){
        QueryWrapper queryWrapperLikeSearch = new QueryWrapper<>();
        queryWrapperLikeSearch.like("title",bookShelf.getTitle());
        List<Novel> listLikeB = list(queryWrapperLikeSearch);
        if (!CollectionUtils.isEmpty(listLikeB)){
            return Result.successMsg(Constants.CODE_200,"找到以下分类",listLikeB);
        } else {
            return Result.error(Constants.CODE_600,"搜索不到此类名称的书籍");
        }
    }
}
